package cn.stylefeng.guns.modular.oa.controller;

import cn.stylefeng.guns.modular.oa.entity.Task;
import cn.stylefeng.guns.modular.oa.pojo.request.TaskRequest;
import cn.stylefeng.guns.modular.oa.service.TaskService;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 控制器
 *
 * @author 王鑫
 * @date 2024/08/07 17:27
 */
@RestController
@ApiResource(name = "工单管理")
public class TaskController {

    @Resource
    private TaskService taskService;

    /**
     * 添加
     *
     * @author 王鑫
     * @date 2024/08/07 17:27
     */
    @PostResource(name = "添加", path = "/task/add")
    public ResponseData<Task> add(@RequestBody @Validated(TaskRequest.add.class) TaskRequest taskRequest) {
        taskService.add(taskRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 删除
     *
     * @author 王鑫
     * @date 2024/08/07 17:27
     */
    @PostResource(name = "删除", path = "/task/delete")
    public ResponseData<?> delete(@RequestBody @Validated(TaskRequest.delete.class) TaskRequest taskRequest) {
        taskService.del(taskRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 编辑
     *
     * @author 王鑫
     * @date 2024/08/07 17:27
     */
    @PostResource(name = "编辑", path = "/task/edit")
    public ResponseData<?> edit(@RequestBody @Validated(TaskRequest.edit.class) TaskRequest taskRequest) {
        taskService.edit(taskRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 查看详情
     *
     * @author 王鑫
     * @date 2024/08/07 17:27
     */
    @GetResource(name = "查看详情", path = "/task/detail")
    public ResponseData<Task> detail(@Validated(TaskRequest.detail.class) TaskRequest taskRequest) {
        return new SuccessResponseData<>(taskService.detail(taskRequest));
    }

    /**
     * 获取列表
     *
     * @author 王鑫
     * @date 2024/08/07 17:27
     */
    @GetResource(name = "获取列表", path = "/task/list")
    public ResponseData<List<Task>> list(TaskRequest taskRequest) {
        return new SuccessResponseData<>(taskService.findList(taskRequest));
    }

    /**
     * 获取列表（带分页）
     *
     * @author 王鑫
     * @date 2024/08/07 17:27
     */
    @GetResource(name = "分页查询", path = "/task/page")
    public ResponseData<PageResult<Task>> page(TaskRequest taskRequest) {
        return new SuccessResponseData<>(taskService.findPage(taskRequest));
    }

}
